package com.example.OnlineStorage.pojo.entity;

import com.example.OnlineStorage.enums.GlobalVariables_String;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.math.BigInteger;
import java.util.Date;

@Data
@Builder
@AllArgsConstructor
public class User {

    @Schema(description = "用户ID")
    private Long id;

    @Schema(description = "用户昵称")
    private String nickname;

    @Schema(description = "用户头像URL")
    private String avatarUrl;

    @Schema(description = "用户名")
    @NotBlank(message = "用户名不能为空")
    @Size(min = 3, max = 255, message = "用户名长度必须在3到255个字符之间")
    private String username;

    @Schema(description = "用户邮箱")
    private String email;

    @Schema(description = "用户密码")
    @NotBlank(message = "密码不能为空")
    @Size(min = 8, max = 255, message = "密码长度必须在8到255个字符之间")
    private String password;

    @Schema(description = "用户注册时间")
    private Date creationTime;

    @Schema(description = "用户文件信息JSON字符串")
    private String fileDataJson;
    
    @Schema(description = "用户存储的大小")
    private BigInteger size;
    
    
    public User() {
    
    }
    public User(String UsernameOrEmail, String password){
        System.out.println(UsernameOrEmail);
        this.username = UsernameOrEmail;
        this.email = UsernameOrEmail;
        this.password = password;
    }

    
    /**
     * 将JSON字符串转换为User对象。
     *
     * @param json JSON字符串
     * @return User对象实例
     */
    public static User fromJson(String json) {
        Gson gson = new GsonBuilder().create();
        return gson.fromJson(json, User.class);
    }
    
    /**
     * 将User对象转换为JSON字符串。
     *
     * @return JSON字符串
     */
    public String toJson() {
        Gson gson = new GsonBuilder().create();
        return gson.toJson(this);
    }

    // 用户令牌的全局变量
    final static String TOKEN = GlobalVariables_String.TOKEN.getValue();
}
